<template>
  <div id="KnowledgeFront">
    <Breadcrumb content="知识库管理" />
    <div class="bodyContent">
      <el-scrollbar style="width: 100%; height: 100%">
        <div class="vforItems">
          <NoData v-if="knowledgeList.length === 0" :msg="'暂无数据'"></NoData>
          <div v-for="(itm, idx) in knowledgeList" :key="idx" class="imgItem">
            <router-link :to="{ path: '/knowledgeview', query: itm }">
              <img :src="getImagePath + itm.imageName" alt="" style="width: 200px; height: 200px" />
            </router-link>
            <span>{{ itm.name }}</span>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<script setup lang="ts">
// 引入组件区 =========
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import Breadcrumb from '@/components/Breadcrumb.vue';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage'; //提示信息
import NoData from '@/components/NoData.vue';

// 变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let knowledgeList = reactive([]);
let getImagePath = ref((window as any).apiUrl.VITE_SERVER_URL + '/image/');

// ============ 方法定义区
onMounted(() => {
  getKnowledgeList();
});

// 查询知识库列表
function getKnowledgeList() {
  knowledgeList.length = 0;
  const url = '/api/wk/wkKnowledge/findKnowledgeList';
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code === 1) {
        knowledgeList.push(...res.data);
      } else {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取内容失败', VxeNotifyType.error);
    });
}
</script>

<style lang="scss" scoped>
#KnowledgeFront {
  width: 100%;
  height: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    width: calc(100% - 20px);

    .vforItems {
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      .imgItem {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        margin: 0 0 10px 10px;
        width: 16%;
        height: 40%;

        img {
          width: 100%;
          height: 100%;
        }
        span {
          font-size: 18px;
          margin-top: 5px;
        }
      }
    }
  }
}
</style>
